#include "StdAfx.h"
#include "Utility.h"
using namespace  Utility;
//////////////////////////////////////////////////////////////////////////
//class helper definition:
//////////////////////////////////////////////////////////////////////////
Helper::Helper(void)
{
}

Helper::~Helper(void)
{
}

void Helper::errInfoDialog( const TCHAR* msg, const TCHAR* title )
{
	::MessageBox(NULL, msg, title, MB_OK);
}

std::string Helper::convertCStringToString(CString& cstr)
{
	USES_CONVERSION;
	char* fileFullName =W2A(cstr.GetBuffer(cstr.GetLength() + 1));
	std::string str(fileFullName);
	return str;
}

std::string Helper::getCurrentTime()
{
	CTime curTime = CTime::GetCurrentTime();
	std::stringstream sstream, sstream2;
	sstream << curTime.GetYear()
			<< "/"
			<< curTime.GetMonth()
			<< "/"
			<< curTime.GetDay();
	
	sstream2<< curTime.GetHour()
			<< ":"
			<< curTime.GetMinute()
			<< ":"
			<< curTime.GetSecond();

	std::string str, str2;
	sstream >> str;
	sstream2 >> str2;
	return str + " " + str2;
}

//////////////////////////////////////////////////////////////////////////
//TimeCounter definition
//////////////////////////////////////////////////////////////////////////
TimeCounter::TimeCounter( void )
{
	LARGE_INTEGER tmp;
	QueryPerformanceFrequency(&tmp);
	_freq = tmp.QuadPart;
	costTime = 0;
}

TimeCounter::~TimeCounter( void )
{
}

void TimeCounter::Start()
{
	QueryPerformanceCounter(&_begin);
}

void TimeCounter::End()
{
	QueryPerformanceCounter(&_end);
	costTime = ((_end.QuadPart - _begin.QuadPart)*1.0f / _freq);
}

void TimeCounter::Reset()
{
	costTime = 0;
}

float TimeCounter::getElapseTime()
{
	return costTime;
}

